package com.yehun.config;


import com.jagregory.shiro.freemarker.ShiroTags;
import freemarker.cache.TemplateLoader;
import freemarker.template.TemplateException;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.io.IOException;
import java.util.List;

/**
 * Created by Genius on 2016/10/18 0018.
 * http://www.cnblogs.com/jennybackup/p/3904462.html
 * layout
 * http://www.oschina.net/code/snippet_1029551_48966
 */
public class FreeMarkerCustomConfigurer extends FreeMarkerConfigurer {

    @Override
    protected TemplateLoader getAggregateTemplateLoader(List<TemplateLoader> templateLoaders) {
        // return super.getAggregateTemplateLoader(templateLoaders);
        // HtmlTemplateLoader 这个类用来自定义html模板
        return new HtmlTemplateLoader(super.getAggregateTemplateLoader(templateLoaders));
    }

    /**
     * freemarker支持shiro标签
     * <@shiro.principal />
     */
    @Override
    public void afterPropertiesSet() throws IOException, TemplateException {
        super.afterPropertiesSet();
        this.getConfiguration().setSharedVariable("shiro", new ShiroTags());
    }

}